package com.xbongbong.saas.script.tempenum;

import com.xbongbong.saas.enums.WriteOffRecordEnum;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.dictionary.CouponTypeEnum;
import com.xbongbong.saas.enums.dictionary.OrderStatusEnum;
import com.xbongbong.saas.enums.dictionary.WriteOffStatusEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/18 21:01
 * @since v1.0
 */
@Getter
public enum TempWriteOffRecordEnum {
    //模板设计展示字段
    ORDER_TIME(WriteOffRecordEnum.ORDER_TIME),
    ORDER_NO(WriteOffRecordEnum.ORDER_NO),
    ORDER_STATUS(WriteOffRecordEnum.ORDER_STATUS),
    COUPON(WriteOffRecordEnum.COUPON),
    DISTRIBUTOR_ID(WriteOffRecordEnum.DISTRIBUTOR_ID),
            ;


    private WriteOffRecordEnum anEnum;

    TempWriteOffRecordEnum(WriteOffRecordEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempWriteOffRecordEnum> getAllEnum() {
        List<TempWriteOffRecordEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }


    public static void initOrderTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("yyyy-MM-dd HH:mm");
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setDisableListSort(1);
        fieldAttrEntity.setEditable(0);
    }

    public static void initOrderNo(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDisableListSort(1);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.ORDER_NO));
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initOrderStatus(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(OrderStatusEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
        fieldAttrEntity.setDisableListSort(1);
        fieldAttrEntity.setEditable(0);
    }

    public static void initCoupon(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity name = InitExplainsHelper.setField("name", "券名称", "name", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        name.setNoRepeat(1);
        name.setParentAttr(COUPON.anEnum.getAttr());
        name.setRequired(1);
        items.add(name);
        FieldAttrEntity serialNo = InitExplainsHelper.setField("serial_no", "券号", "serialNo", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        serialNo.setNoRepeat(1);
        serialNo.setParentAttr(COUPON.anEnum.getAttr());
        serialNo.setRequired(1);
        serialNo.setTheWidth(300L);
        items.add(serialNo);
        FieldAttrEntity type = InitExplainsHelper.setField("type", "类型", "type", FieldTypeEnum.COMBO.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(CouponTypeEnum.class, FieldTypeEnum.COMBO.getType());
        type.setItems(itemPoJoList);
        type.setRequired(1);
        type.setDictionaryFlag(1);
        type.setParentAttr(COUPON.anEnum.getAttr());
        items.add(type);
        FieldAttrEntity date = InitExplainsHelper.setField("used_date", "核销时间", "usedDate", FieldTypeEnum.DATETIME.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        date.setNoRepeat(1);
        date.setParentAttr(COUPON.anEnum.getAttr());
        date.setRequired(1);
        items.add(date);
        FieldAttrEntity status = InitExplainsHelper.setField("status", "核销状态", "status", FieldTypeEnum.COMBO.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        List<ItemPoJo> statusList = InitExplainsHelper.setCombItemByEnum(WriteOffStatusEnum.class, FieldTypeEnum.COMBO.getType());
        status.setItems(statusList);
        status.setRequired(1);
        status.setDictionaryFlag(1);
        status.setParentAttr(COUPON.anEnum.getAttr());
        items.add(status);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.CUSTOM.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setRequired(1);
        fieldAttrEntity.setDictionaryFlag(1);
        fieldAttrEntity.setIsForbidden(1);
        fieldAttrEntity.setDisableListSort(1);
        fieldAttrEntity.setEditable(0);
    }



    public static void initDistributorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setDisableListSort(1);
        fieldAttrEntity.setEditable(0);
    }


}
